#!/usr/bin/lua
package.cpath = "?;./?.so;/usr/share/internet-wifi/lib.so/?.so;" .. package.cpath 
package.path = "?;./?.lua;/usr/share/internet-wifi/?.lua;/usr/share/internet-wifi/lib/?.lua;/usr/share/internet-wifi/pkgs/?.lua;" .. package.path 
-- Common Functions
require("common")

function check_connection(str)
  local str = str or "google.com"
  ping = io.popen("ping -c 1 "..str)
  local ok = false
  for line in ping:lines() do
    if string.match(line,"1 packets received") then
      ok = true
      print(string.match(line,"1 packets received"))
    end
  end
  if ok == false then
  os.execute("ifup wan") 
--  os.execute("/etc/init.d/olsrd restart") 
  end

end

check_connection()
